package hqyj.example.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import hqyj.example.provider.domain.Goods;
import hqyj.example.provider.mapper.GoodsMapper;
import hqyj.example.provider.service.GoodsService;
import hqyj.example.provider.view.Catalog;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {


    @Override
    public List<Goods> queryAllGoodsList() {
        return super.list();
    }

    @Override
    public List<Goods> queryAllGoodsListByCatalog(String catalog) {
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<Goods>();
        queryWrapper.eq("catalog",catalog);
        return super.list(queryWrapper);
    }

    @Override
    public List<Catalog> queryAllCatalogList() {
        List<Catalog> catalogList = new ArrayList<Catalog>();
        QueryWrapper<Goods> queryWrapper = new QueryWrapper<Goods>();
        queryWrapper.select("DISTINCT catalog");
        List<Goods> goodsList =super.list(queryWrapper);
        for(int i=0;i<goodsList.size();i++){
            Catalog c = new Catalog();
            c.setName(goodsList.get(i).getCatalog());
            c.setId(i);
            catalogList.add(c);
        }
        return catalogList;
    }
}
